package com.hx.myfristandriod;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

public class TestAlertActivity extends Activity{

	private Dialog dialog;
	private Button btnShow;
	private TextView txtShouName;
    @Override
	protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
       setContentView(R.layout.alert_test);
       btnShow=(Button) findViewById(R.id.btnShow);
       txtShouName=(TextView) findViewById(R.id.txtShowName);
       Intent intent=getIntent();
       String txtName=intent.getStringExtra("txtName");
       this.txtShouName.setText(txtName);
       
       //按钮监听事件，点击触发
       btnShow.setOnClickListener(new OnClickListener() {
		@Override
		public void onClick(View v) {
			 switch (v.getId()) {
		    	case R.id.btnShow:
				        dialog.show();
			        	break;
		     	default:
			    	    break;
		    	}
		}
	});
 
       //构建dialog对象
       this.dialog=new AlertDialog.Builder(this)
       .setIcon(android.R.drawable.ic_lock_idle_lock)
       .setTitle("标题")
       .setMessage("对话框内容")
       .setPositiveButton("确定", new DialogOcl())
       .setNegativeButton("取消", new DialogOcl())
       .create();
       
    }
     
    //绑定对话框事件
    class DialogOcl implements DialogInterface.OnClickListener{
		@Override
		public void onClick(DialogInterface dialog, int which) {
			switch (which) {
		     	case DialogInterface.BUTTON_POSITIVE:
				System.out.println("点击了确定按钮");
				break;
	            case DialogInterface.BUTTON_NEGATIVE:
	        		System.out.println("点击了取消按钮");
				break;
			default:
				break;
			}
		}
    }
    	
}
